export default {
  namespaced: true,

  state: {
    isShowToast: false,
    //提示信息
    toastMsg: "提示信息",
    //提示类型
    toastType: "danger", //success   warning
  },
  mutations: {
    // 修改提示框状态的方法
    changeIsShowToast(state, payload) {
      state.isShowToast = payload.isshow;
      if (payload.isshow) {
        state.toastMsg = payload.msg;
        state.toastType = payload.type;
      }
      //在这里统一关闭(异步代码!!!!应该放在action中。)
    },
  },

  actions: {
    asyncChangeIsShowToast({ commit }, payload) {
      // 调用mutation 设置显示
      commit("changeIsShowToast", payload);
      // 调用mutation 设置隐藏

      setTimeout(() => {
        commit("changeIsShowToast", {
          isshow: false,
        });
      }, 2000);
    },
  },
};
